<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> JS </title>
    <script src="jquery.min.js"> </script>
</head>
<body>
    <!-- <input type = "button" value = " 添 加 " onclick="add('张三','123')">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type = "button" value = " 修 改 " onclick="up('李四','123456')">&nbsp;&nbsp;&nbsp;&nbsp;
    <input type = "button" value = " 删 除 " >&nbsp;&nbsp;&nbsp;&nbsp;
    <input type = "button" value = " 查 询 " >&nbsp;&nbsp;&nbsp;&nbsp; -->
    <img id="img1" width="200px" src="dog.jpg">
    <p></p>

    <h3>猜数字游戏<h3>
        玩家输入一个 1-10的数字：<input id = "input_num" type="text"> <p></p>
        <input type="button" value="查看结果" onclick="selectResultJq()">
        <div id = "result_div">
            </div>

    <input onclick="upImg()" type = "button" value = "更换图片">
    <hr>

    <script>
        // function up() {
        //     alert("执行了修改方法！\n");

        //     for(var item of arguments) {
        //         console.log(item);
        //     }
        // }

        // //添加方法
        // function add(name,password) {
        //     alert("执行了添加方法！\n name="+name+"\n password="+password);
        //     return "hello world!";
        // }
        // var result = add();
        // console.log(result);

        // unsafe -> CAS
        // var functionName = prompt("输入方法名：");
        // eval(functionName+"()");

        // var student = {
        //     id:123,
        //     name:"张三",
        //     password:"123",

        //     sayHi:function() {
        //         alert("hi student");
        //     }
        // };

        // console.log(student.name);
        // student.sayHi();
        function selectResultJq() {
            var randomNum = 1+Math.floor(Math.random()*10);
            var useInputNum = jQuery("#input_num").val();
            if(randomNum == useInputNum) {
                msg = "<h4>恭喜，猜对了</h4>";
            }else {
                msg = "<h4>抱歉，猜错了 正确的数字是："+randomNum+"</h4>";
            }
            // document.getElementById("result_div").innerHTML = msg;
            jQuery("#result_div").html(msg);
        }

         //原生js查询
        function upImg() {
            var sg_img = "1.jpg";
            document.getElementById("img1").src = sg_img;
        }
       //原生js猜数字
        function selectResult() {
            //产生随机数
            var randomNum = 1+Math.floor(Math.random()*10);
            var useInputNum = document.getElementById("input_num").value;
            var msg;
            if(randomNum == useInputNum) {
                msg = "<h4>恭喜，猜对了</h4>";
            }else {
                msg = "<h4>抱歉，猜错了 正确的数字是："+randomNum+"</h4>";
            }
            document.getElementById("result_div").innerHTML = msg;
        }
        </script>
    
</body>
</html>